<?php
class Home extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('url');
		$this->load->library('encrypt');
		$this->load->model('Mhome');
	}
	
	function index(){
		//$data['page_title'] = "新闻发布系统";
		//$this->load->view('header', $data);
		//$this->load->view('left', $data);
		$data['user_id'] = "";
		$data['user_pwd'] = "";
		$this->load->view('header', $data);
		$this->load->view('left');
		$this->load->view('content');
		$this->load->view('footer');
		
	}
	
	function pre_regist(){
		$this->load->view('regist1.php');
	}
	
	function regist_1(){
		if ($this->input->post('submit')) {
 			
 			$query = $this->Mhome->insert_user();
 			if ($query) {
 				//redirect('home/content/'.$this->input->post('article_id'));
 				$data['user_id'] = $this->input->post('user_id');
 				$this->load->view('regist2.php', $data);
 				return;
 			}
 		}
		$this->load->view('regist1.php');
	}
	
	function regist_2(){
		if ($this->input->post('submit')) {
 			$row = $this->Mhome->get_user($this->input->post('user_id'));
 			if($row){
 				$row->almm_id = $this->input->post('almm_id');
	 			$query = $this->Mhome->update_user($row);
	 			if ($query) {
	 				//redirect('home/content/'.$this->input->post('article_id'));
	 				$data['user_id'] = $this->input->post('user_id');
	 				
	 				$this->load->library('email');

					$this->email->from('Support@loveshowlovelife.com', 'Administrator');
					$this->email->to($this->input->post('user_id')); 
					
					$this->email->subject('这是一封激活邮件');
					//site_url('home/active_user')
					$msg = '<a href="http://localhost:9091/taoke/index.php/home/active_user?guid=49631f0f-65a8-102f-aab8-44d24f157b29">点击这里激活帐号！</a>';
				    $this->email->message($msg); 
					$this->email->send();
	 				$data['msg'] = '<a href="'.site_url('home/active_user').'?guid=' + $row->active_key + '">点击这里激活帐号！</a>';
	 				$this->load->view('regist3.php', $data);
	 				return;
	 			}
 			}
 		}
		$this->load->view('regist2.php');
	}
	
	function active_user(){
//		$active_key = $_GET['guid'];//parse_str($_SERVER['active_key'], $_GET);//$this->input->get('active_key');
		$row = $this->Mhome->get_user_1($_GET['guid']);
		if($row){
			$this->Mhome->active_user($_GET['guid']);
			$this->session->set_userdata('user_id', $row->user_id);
			redirect('home/mypage');
		}else{
			//redirect('home/index');
		}
	}
	
	function mypage(){
		$this->load->view('iheader');
		$this->load->view('left');
		$this->load->view('icontent');
		$this->load->view('footer');
	}
	
	function check_login(){
		$user_id = $this->input->post('user_id');
		$user_pwd = $this->encrypt->encode($this->input->post('user_pwd'));
		
 		$row = $this->Mhome->get_user($user_id, $user_pwd);
 		$data['output'] = $row?"true":"false";
 		$this->load->view('ajax.php', $data);
	}
	
	function login(){
		$user_id = $this->input->post('user_id');
		$user_pwd = $this->encrypt->encode($this->input->post('user_pwd'));
		
		$row = $this->Mhome->get_user($user_id, $user_pwd);
		if($row){
			$this->session->set_userdata('user_id', $this->input->post('user_id'));
			$this->load->view('iheader');
			$this->load->view('left');
			$this->load->view('icontent');
			$this->load->view('footer');
		}else{
			
		}
	}
	
	function validate_regist(){
		/*
		$query = $this->photomodel->get_Pic($this->input->post('id')); // 对应jquery里面的 "id=" + $(this).attr("id"),  
  
		if($query->num_rows() > 0) {
			$row = $query->row();
			$output = "photo_infomation";
		}else{
			$output = "no picture was found";
		}

		$this->output->append_output($output);*/
	}
}